package com.leetcode.q9;

/**
 * <p> description: desc</p>
 *
 * @author tanzc
 * @date 2022/3/30
 **/
public class IsPalindRome {
    public static void main(String[] args) {
        IsPalindRome soltuion = new IsPalindRome();
        System.out.println(soltuion.isPalindrome(-121));
    }

    public boolean isPalindrome(int x) {
        if (x < 0) {
            return false;
        }
        if (x < 10) {

            return true;
        }
        String s = "" + x;
        int l = 0, r = s.length() - 1;
        while (l < r) {
            if (s.charAt(l) != s.charAt(r)) {
                return false;
            }
            l++;
            r--;
        }
        return true;
    }

    public boolean isPalindrome1(int x) {

        if (x < 0) {
            return false;
        }
        if (x < 10) {

            return true;
        }
        int xx = x;
        int y = 0;
        while (xx != 0) {
            y = y * 10 + xx % 10;
            xx = xx / 10;
        }
        return x == y;
    }
}
